package com.easyidea.its.domain.service.surveillance.impl;

import java.util.Collection;

import com.easyidea.its.domain.model.surveillance.CancleSurveillance;
import com.easyidea.its.domain.model.surveillance.Surveillance;
import com.easyidea.its.domain.repository.surveillance.CancleSurveillanceRepository;
import com.easyidea.its.domain.repository.surveillance.SurveillanceRepository;
import com.easyidea.its.domain.service.base.impl.BaseBeanServiceImpl;
import com.easyidea.its.domain.service.surveillance.CancleSurveillanceService;
import com.easyidea.its.web.action.surveillance.dto.SurveillanceDto;

/**
 * 
 * @author hukn
 * 
 */
public class CancleSurveillanceServiceImpl extends BaseBeanServiceImpl<CancleSurveillance, CancleSurveillanceRepository> implements
		CancleSurveillanceService {
	private CancleSurveillanceRepository cancleSurveillanceRepository;
	private SurveillanceRepository surveillanceRepository;

	public SurveillanceRepository getSurveillanceRepository() {
		return surveillanceRepository;
	}

	public void setSurveillanceRepository(
			SurveillanceRepository surveillanceRepository) {
		this.surveillanceRepository = surveillanceRepository;
	}

	@Override
	public CancleSurveillanceRepository getBaseRepository() {
		return cancleSurveillanceRepository;
	}

	public CancleSurveillanceRepository getCancleSurveillanceRepository() {
		return cancleSurveillanceRepository;
	}

	public void setCancleSurveillanceRepository(CancleSurveillanceRepository cancleSurveillanceRepository) {
		this.cancleSurveillanceRepository = cancleSurveillanceRepository;
	}

	public int getSurveillanceCountByDto(SurveillanceDto searchDto) {

		return cancleSurveillanceRepository.getSurveillanceCountByDto(searchDto);
	}

	public Collection<CancleSurveillance> getSurveillanceByDto(SurveillanceDto searchDto, int start, int pageSize) {

		return cancleSurveillanceRepository.getSurveillanceByDto(searchDto, start, pageSize);
	}

	public boolean saveCancleSurveillance(CancleSurveillance cancleSurveillance) {
		CancleSurveillance savedBean = this.getBeanById(cancleSurveillance.getId());
		if (savedBean == null) {
			this.saveOrUpdateBean(cancleSurveillance);
			Surveillance sur = surveillanceRepository.getBeanById(cancleSurveillance.getId());
			sur.setActive(false);
			surveillanceRepository.saveOrUpdateBean(sur);
			return true;
		}
		return false;
	}

}
